<?php

declare(strict_types=1);

namespace app\user\controller\admin;

use think\Request;
use think\facade\Db;
use sheep\controller\Backend;
use sheep\exception\SheepException;
use app\user\model\WalletLog as WalletLogModel;
use sheep\library\Operator;

class WalletLog extends Backend
{
    protected $model = null;

    protected function initialize()
    {
        $this->model = new WalletLogModel;
    }

    /**
     * 用户列表
     *
     * @return \think\Response
     */
    public function money(Request $request, $id)
    {
        $list_rows = $request->param('list_rows', 10);
        $data = WalletLogModel::where('user_id', $id)->money()->with('oper')->order('create_time', 'desc')->paginate((int)$list_rows)->toArray();
        // 解析操作人信息
        foreach ($data['data'] as &$log) {
            $log['oper'] = Operator::info($log['oper_type'], $log['oper'] ?? null);
        }
        return success('', $data);
    }

    /**
     * 用户列表
     *
     * @return \think\Response
     */
    public function score(Request $request, $id)
    {
        $list_rows = $request->param('list_rows', 10);
        $data = WalletLogModel::where('user_id', $id)->score()->with('oper')->order('create_time', 'desc')->paginate((int)$list_rows)->toArray();
        // 解析操作人信息
        foreach ($data['data'] as &$log) {
            $log['oper'] = Operator::info($log['oper_type'], $log['oper'] ?? null);
        }
        return success('', $data);
    }

    /**
     * 用户列表
     *
     * @return \think\Response
     */
    public function commission(Request $request, $id)
    {
        $type = $request->param('type', 'money');
        $list_rows = $request->param('list_rows', 10);
        $data = WalletLogModel::where('user_id', $id)->commission()->order('create_time', 'desc')->with('oper')->paginate((int)$list_rows)->toArray();
        // 解析操作人信息
        foreach ($data['data'] as &$log) {
            $log['oper'] = Operator::info($log['oper_type'], $log['oper'] ?? null);
        }
        return success('', $data);
    }
}
